package com.lc.cms.contoller;

import com.lc.cms.dto.DepartmentPermissionDto;
import com.lc.cms.model.DepartmentModel;
import com.lc.cms.service.IDepartmentService;
import com.lc.cms.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("department")
@Log4j2
public class DepartmentController {

    private final IDepartmentService departmentService;

    @Autowired
    public DepartmentController(IDepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @RequestMapping("create")
    public ResponseResult create(DepartmentModel department) {
        Long start = new Date().getTime();
        ResponseResult responseResult = departmentService.create(department);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult update(DepartmentModel department) {
        Long start = new Date().getTime();
        ResponseResult responseResult = departmentService.update(department);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("delete")
    public ResponseResult delete(int id) {
        Long start = new Date().getTime();
        ResponseResult responseResult = departmentService.delete(id);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("updateDepartmentPermission")
    public ResponseResult updateDepartmentPermission(DepartmentPermissionDto department) {
        Long start = new Date().getTime();
        ResponseResult responseResult = departmentService.updateDepartmentPermission(department);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
